package cn.the.angry.tests;


public class PigLaunchTest extends AbstractTest
{
//	private final Animation ball;
//	private final List<PhysicalObject> physicalObjects=new LinkedList<PhysicalObject>();
//	private final Vec2 groundSize;
//	private final Body groundBody;
//	private final DebugDraw m_debugDraw;
//	private final World m_world;
//	private final AABB m_worldAABB;
//	private enum LauncherState{READY,BEFORE_LAUNCH,AFTER_LAUNCH,UNAVAILABLE};
//	private LauncherState state=LauncherState.READY;
//	private final Point ORIBALLPOSTION=new Point(200, HEIGHT-390);
//	private final Point ROPEPOINT1=new Point(ORIBALLPOSTION.x+25,ORIBALLPOSTION.y+20);
//	private final Point ROPEPOINT2=new Point(ORIBALLPOSTION.x-15,ORIBALLPOSTION.y+20);
//	private enum ObjectDataKeyType {DRAWRECTPOINTX1,DRAWRECTPOINTY1,DRAWRECTPOINTX2,DRAWRECTPOINTY2,X,Y,PX,PY};
//	
//	public PigLaunchTest()
//	{
//		super();
//		m_debugDraw=new DrawUtil(displayBufferImage);
//		m_worldAABB=new AABB();
//		m_worldAABB.lowerBound.set(new Vec2(-10, -10));
//		m_worldAABB.upperBound.set(new Vec2(1000, 1000));
//		m_world=new World(m_worldAABB, new Vec2(0f,10f), true);
//		m_world.setDebugDraw(m_debugDraw);
//		m_world.setWarmStarting(true);
//		m_world.setPositionCorrection(true);
//		m_world.setContinuousPhysics(true);
//		m_debugDraw.setFlags(0);
//		m_debugDraw.appendFlags(DebugDraw.e_shapeBit);
//		m_debugDraw.appendFlags(DebugDraw.e_jointBit);
//		m_debugDraw.appendFlags(DebugDraw.e_coreShapeBit);
//		m_debugDraw.appendFlags(DebugDraw.e_aabbBit);
//		m_debugDraw.appendFlags(DebugDraw.e_obbBit);
//		m_debugDraw.appendFlags(DebugDraw.e_pairBit);
//		m_debugDraw.appendFlags(DebugDraw.e_centerOfMassBit);
//		m_debugDraw.appendFlags(DebugDraw.e_controllerBit);
//		m_debugDraw.setCamera(0, 0, 1f);
//		
//		groundSize=new Vec2(WIDTH, 200);
//		PolygonDef groundPolygonDef = new PolygonDef();
//		groundPolygonDef.setAsBox(groundSize.x/2, groundSize.y/2);
//
//		BodyDef groundBodyDef = new BodyDef();
//		groundBodyDef.position = new Vec2(groundSize.x/2, HEIGHT-groundSize.y/2);
//		groundBody=m_world.createBody(groundBodyDef);
//		groundBody.createShape(groundPolygonDef);
//		
//		ball=new Animation(ResourceManager.getMiddleWoodBallImages());
//		ball.setData(ObjectDataKeyType.X, ORIBALLPOSTION.x);
//		ball.setData(ObjectDataKeyType.Y, ORIBALLPOSTION.y);
//		
//	}
//
//	public void step(float dt, int iterations)
//	{
//		m_world.step(dt, iterations);
//		final Graphics2D g2d=displayBufferImage.createGraphics();
//		Vec2 drawRectPoint1=new Vec2(),drawRectPoint2=new Vec2();
//		final int[] repaintPoint=new int[ physicalObjects.size()*4 ];
//		final int OFFSET=3;
//		
//		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//		
//		for(int i=0; i<physicalObjects.size(); ++i)
//		{
//			final PhysicalObject physicalObject=physicalObjects.get(i);	
//			if(physicalObject.getData(ObjectDataKeyType.DRAWRECTPOINTX1)!=null)
//			{
//				final int repaintPoint1X=repaintPoint[i*4]=((Float) physicalObject.getData(ObjectDataKeyType.DRAWRECTPOINTX1)).intValue();
//				final int repaintPoint1Y=repaintPoint[i*4+1]=((Float) physicalObject.getData(ObjectDataKeyType.DRAWRECTPOINTY1)).intValue();
//				final int repaintPoint2X=repaintPoint[i*4+2]=((Float) physicalObject.getData(ObjectDataKeyType.DRAWRECTPOINTX2)).intValue();
//				final int repaintPoint2Y=repaintPoint[i*4+3]=((Float) physicalObject.getData(ObjectDataKeyType.DRAWRECTPOINTY2)).intValue();
//			
//				g2d.drawImage(backgroundBufferImage, repaintPoint1X-OFFSET, repaintPoint1Y-OFFSET, 
//						repaintPoint2X+OFFSET, repaintPoint2Y+OFFSET, 
//						repaintPoint1X-OFFSET, repaintPoint1Y-OFFSET, 
//						repaintPoint2X+OFFSET, repaintPoint2Y+OFFSET, null);
//			}
//		}
//		
//		for(int i=0; i<physicalObjects.size(); ++i)
//		{
//			final PhysicalObject physicalObject=physicalObjects.get(i);
//			Integer repaintPoint1X=null,repaintPoint1Y=null,repaintPoint2X=null,repaintPoint2Y=null;
//			if(physicalObject.getData(ObjectDataKeyType.DRAWRECTPOINTX1)!=null)
//			{
//				repaintPoint1X=repaintPoint[i*4];
//				repaintPoint1Y=repaintPoint[i*4+1];
//				repaintPoint2X=repaintPoint[i*4+2];
//				repaintPoint2Y=repaintPoint[i*4+3];
//			}
//			
//			drawRectPoint1.x=physicalObject.getLocation().x;
//			drawRectPoint1.y=physicalObject.getLocation().y;
//			drawRectPoint2.x=physicalObject.getLocation().x+physicalObject.getFrameWidth();
//			drawRectPoint2.y=physicalObject.getLocation().y+physicalObject.getFrameHeight();
//			
//			m_debugDraw.getWorldToScreenToOut(drawRectPoint1, drawRectPoint1);
//			m_debugDraw.getWorldToScreenToOut(drawRectPoint2, drawRectPoint2);
//			
//			physicalObject.setData(ObjectDataKeyType.DRAWRECTPOINTX1, drawRectPoint1.x);
//			physicalObject.setData(ObjectDataKeyType.DRAWRECTPOINTY1, drawRectPoint1.y);
//			physicalObject.setData(ObjectDataKeyType.DRAWRECTPOINTX2, drawRectPoint2.x);
//			physicalObject.setData(ObjectDataKeyType.DRAWRECTPOINTY2, drawRectPoint2.y);
//			
//			g2d.drawImage(physicalObject.getImage(), (int) drawRectPoint1.x, (int) drawRectPoint1.y, 
//					(int) (drawRectPoint2.x-drawRectPoint1.x), (int) (drawRectPoint2.y-drawRectPoint1.y), null);
//			
//			if(repaintPoint1X==null || repaintPoint1X>repaintPoint[i*4]) 
//				repaintPoint1X=repaintPoint[i*4];
//			if(repaintPoint1Y==null || repaintPoint1Y>repaintPoint[i*4+1])
//				repaintPoint1Y=repaintPoint[i*4+1];
//			if(repaintPoint2X==null || repaintPoint2X<repaintPoint[i*4+2]) 
//				repaintPoint2X=repaintPoint[i*4+2];
//			if(repaintPoint2Y==null || repaintPoint1Y>repaintPoint[i*4+3]) 
//				repaintPoint2Y=repaintPoint[i*4+3];
//			
//			repaintPoint[4*i]=repaintPoint1X;
//			repaintPoint[4*i+1]=repaintPoint1Y;
//			repaintPoint[4*i+2]=repaintPoint2X;
//			repaintPoint[4*i+3]=repaintPoint2Y;
//		}
//				
//		for(int i=0; i<4*physicalObjects.size(); i+=4)
//		{	
//			g2d.drawImage(foregroundBufferImage, repaintPoint[i]-OFFSET, repaintPoint[i+1]-OFFSET, 
//					repaintPoint[i+2]+OFFSET, repaintPoint[i+3]+OFFSET, 
//					repaintPoint[i]-OFFSET, repaintPoint[i+1]-OFFSET,
//					repaintPoint[i+2]+OFFSET, repaintPoint[i+3]+OFFSET, null);
//			
//			this.getGraphics().drawImage(displayBufferImage, repaintPoint[i]-OFFSET, repaintPoint[i+1]-OFFSET, 
//					repaintPoint[i+2]+OFFSET, repaintPoint[i+3]+OFFSET, 
//					repaintPoint[i]-OFFSET, repaintPoint[i+1]-OFFSET,
//					repaintPoint[i+2]+OFFSET, repaintPoint[i+3]+OFFSET, null);
//		}
//		
//		if(state==LauncherState.READY || state==LauncherState.BEFORE_LAUNCH)
//		{
//			Integer repaintPoint1X=null,repaintPoint1Y=null,repaintPoint2X=null,repaintPoint2Y=null;
//			repaintPoint1X=(Integer) ball.getData(ObjectDataKeyType.PX);
//			repaintPoint1Y=(Integer) ball.getData(ObjectDataKeyType.PY);
//			if(repaintPoint1X!=null && repaintPoint1Y!=null)
//			{
//				repaintPoint2X=repaintPoint1X+ball.getFrameWidth();
//				repaintPoint2Y=repaintPoint1Y+ball.getFrameHeight();
//				
//				if(repaintPoint1X>Math.min(ROPEPOINT1.x, ROPEPOINT2.x))
//					repaintPoint1X=Math.min(ROPEPOINT1.x, ROPEPOINT2.x);
//				if(repaintPoint2X<Math.max(ROPEPOINT1.x, ROPEPOINT2.x))
//					repaintPoint2X=Math.max(ROPEPOINT1.x, ROPEPOINT2.x);
//				if(repaintPoint1Y>Math.min(ROPEPOINT1.y, ROPEPOINT2.y))
//					repaintPoint1Y=Math.min(ROPEPOINT1.y, ROPEPOINT2.y);
//				if(repaintPoint2Y<Math.max(ROPEPOINT1.y, ROPEPOINT2.y))
//					repaintPoint2Y=Math.max(ROPEPOINT1.y, ROPEPOINT2.y);
//				
//				g2d.drawImage(backgroundBufferImage,repaintPoint1X-OFFSET,repaintPoint1Y-OFFSET,
//						repaintPoint2X+OFFSET,repaintPoint2Y+OFFSET,
//						repaintPoint1X-OFFSET,repaintPoint1Y-OFFSET,
//						repaintPoint2X+OFFSET,repaintPoint2Y+OFFSET,null);
//			}			
//									
//			ball.setData(ObjectDataKeyType.PX, ball.getData(ObjectDataKeyType.X));
//			ball.setData(ObjectDataKeyType.PY, ball.getData(ObjectDataKeyType.Y));
//						
//			g2d.setStroke(new BasicStroke(3f));
//			g2d.setColor(Color.BLACK);
//			g2d.drawLine(ROPEPOINT1.x, ROPEPOINT1.y, 
//					(Integer) ball.getData(ObjectDataKeyType.X)+ball.getFrameWidth()/2, 
//					(Integer) ball.getData(ObjectDataKeyType.Y)+ball.getFrameHeight()/2);
//			
//			g2d.drawImage(ball.getImage(),
//					(Integer) ball.getData(ObjectDataKeyType.X),
//					(Integer) ball.getData(ObjectDataKeyType.Y),
//					ball.getFrameWidth(),ball.getFrameHeight(),null);
//						
//			g2d.drawLine(ROPEPOINT2.x, ROPEPOINT2.y, 
//					(Integer) ball.getData(ObjectDataKeyType.X)+ball.getFrameWidth()/2, 
//					(Integer) ball.getData(ObjectDataKeyType.Y)+ball.getFrameHeight()/2);
//			
//			if(repaintPoint1X==null || repaintPoint1X>(Integer) ball.getData(ObjectDataKeyType.X))
//				repaintPoint1X=(Integer) ball.getData(ObjectDataKeyType.X);
//			
//			if(repaintPoint1Y==null || repaintPoint1Y>(Integer) ball.getData(ObjectDataKeyType.Y))
//				repaintPoint1Y=(Integer) ball.getData(ObjectDataKeyType.Y);
//			
//			if(repaintPoint2X==null || repaintPoint2X<(Integer) ball.getData(ObjectDataKeyType.X)+ball.getFrameWidth())
//				repaintPoint2X=(Integer) ball.getData(ObjectDataKeyType.X)+ball.getFrameWidth();
//			
//			if(repaintPoint2Y==null || repaintPoint2Y<(Integer) ball.getData(ObjectDataKeyType.Y)+ball.getFrameHeight())
//				repaintPoint2Y=(Integer) ball.getData(ObjectDataKeyType.Y)+ball.getFrameHeight();
//						
//			g2d.drawImage(foregroundBufferImage, 
//					repaintPoint1X-OFFSET, repaintPoint1Y-OFFSET, repaintPoint2X+OFFSET, repaintPoint2Y+OFFSET, 
//					repaintPoint1X-OFFSET, repaintPoint1Y-OFFSET, repaintPoint2X+OFFSET, repaintPoint2Y+OFFSET, null);
//			
//			this.getGraphics().drawImage(displayBufferImage, 
//					repaintPoint1X-OFFSET, repaintPoint1Y-OFFSET, repaintPoint2X+OFFSET, repaintPoint2Y+OFFSET, 
//					repaintPoint1X-OFFSET, repaintPoint1Y-OFFSET, repaintPoint2X+OFFSET, repaintPoint2Y+OFFSET, null);
//		}
//		
//		g2d.dispose();
//	}
//	
//	public void mouseOnPigAndDown(final MouseEvent e)
//	{
//		if(state==LauncherState.READY)
//			state=LauncherState.BEFORE_LAUNCH;
//	}
//	
//	public void mouseOnPigAndUp(final MouseEvent e)
//	{
//		if(state==LauncherState.BEFORE_LAUNCH)
//		{
//			state=LauncherState.AFTER_LAUNCH;
//			PhysicalObject physicalObject=new PhysicalObject(ball);
//			physicalObjects.add(physicalObject);
//			
//			final CircleDef testCircleDef=new CircleDef();
//			testCircleDef.density=1.0f;
//			testCircleDef.friction=1.0f;
//			testCircleDef.radius=ball.getFrameWidth()/2;
//			testCircleDef.restitution=0.9f;
//			
//			final BodyDef testCircleBodyDef=new BodyDef();
//			testCircleBodyDef.allowSleep=true;
//			testCircleBodyDef.position=new Vec2((Integer) ball.getData(ObjectDataKeyType.X),(Integer) ball.getData(ObjectDataKeyType.Y));
//			
//			physicalObject.setObjectBody(m_world.createBody(testCircleBodyDef));
//			physicalObject.getObjectBody().createShape(testCircleDef);
//			physicalObject.getObjectBody().setMassFromShapes();
//			physicalObject.setLinearVelocity(new Vec2(2*(ORIBALLPOSTION.x-(Integer) ball.getData(ObjectDataKeyType.X)), 2*(ORIBALLPOSTION.y-(Integer) ball.getData(ObjectDataKeyType.Y))));
//		}
//	}
//	
//	public void mouseOnPidAndDrag(final MouseEvent e)
//	{
//		if(state==LauncherState.BEFORE_LAUNCH && 
//		   e.getX()>(Integer) ball.getData(ObjectDataKeyType.X) && e.getX()<((Integer) ball.getData(ObjectDataKeyType.X)+ball.getFrameWidth()) &&
//		   e.getY()>(Integer) ball.getData(ObjectDataKeyType.Y) && e.getY()<((Integer) ball.getData(ObjectDataKeyType.Y)+ball.getFrameHeight()))
//		{
//			int x=e.getX()-ball.getFrameWidth()/2, y=e.getY()-ball.getFrameHeight()/2;
//			int z=(int) Math.sqrt(Math.pow(x-ORIBALLPOSTION.x,2)+Math.pow(y-ORIBALLPOSTION.y,2));
//			if(z>100)
//			{
//				x=100*(x-ORIBALLPOSTION.x)/z+ORIBALLPOSTION.x;
//				y=100*(y-ORIBALLPOSTION.y)/z+ORIBALLPOSTION.y;
//			}
//			
//			ball.setData(ObjectDataKeyType.X, x);
//			ball.setData(ObjectDataKeyType.Y, y);
//		}
//	}
//	
//	public static void main(String[] args)
//	{
//		final PigLaunchTest main = new PigLaunchTest();
//        main.setVisible(true);
//        main.getContentPane().getComponent(0).repaint();
//        main.addMouseListener(new MouseAdapter()
//		{        	
//        	@Override
//        	public void mousePressed(MouseEvent e)
//        	{
//        		main.mouseOnPigAndDown(e);
//        	}
//        	
//        	@Override
//        	public void mouseReleased(MouseEvent e)
//        	{
//        		main.mouseOnPigAndUp(e);
//        	}
//		});
//        
//        main.addMouseMotionListener(new MouseMotionAdapter()
//		{
//			@Override
//			public void mouseDragged(MouseEvent e)
//			{
//				main.mouseOnPidAndDrag(e);
//			}
//		});
//        
//        new Thread(new Runnable()
//        {    
//            @Override
//            public void run()
//            {
//                for(;;)
//                {
//                	try
//					{
//						Thread.sleep(5);
//					}
//					catch (InterruptedException e)
//					{
//						e.printStackTrace();
//					}
//                    final float timeStep=1/60f;
//            		final int iterationCount=10;
//            		main.step(timeStep, iterationCount);            		
//                }
//            }
//            
//        }).start();
//	}
}
